﻿@{
    Layout = "_LayoutH";
    @model Sys_user
}
<div id="app" v-cloak>
    <form class="form-horizontal" onsubmit="return false">
        <div class="box-body">
            <table class="table table-bordered">
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span class="c-red">*</span>用户名：</label>
                            <div class="col-sm-10">
                                <input v-model="UserName" readonly type="text" class="form-control">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <label class="control-label col-sm-2"><span class="c-red">*</span>昵称：</label>
                            <div class="col-sm-10">
                                <input type="text" readonly v-model="UserNickname" class="form-control">
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span class="c-red">*</span>原密码：</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" autocomplete="off" v-focus placeholder="原密码" v-model="OldPwd">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <label class="control-label col-sm-2"><span class="c-red">*</span>新密码：</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" autocomplete="off" placeholder="新密码" v-model="Pwd1">
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            <label class="control-label col-sm-2"><span class="c-red">*</span>确认新密码：</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" autocomplete="off" placeholder="确认新密码" v-model="Pwd2">
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            <div class="box-footer">
                <div class="pull-right box-tools">
                    <input v-on:click="addL" class="btn btn-primary radius" type="submit" v-model="submit">
                </div>
            </div>
        </div>
    </form>
</div>
@section scripts{
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                submit: "添加",
                UserName: "@Model.UserName",
                UserNickname: "@Model.UserNickname",
                UserId:"@Model.UserId",
                OldPwd: "",
                Pwd1: "",
                Pwd2: ""
            },
            methods: {
                addL: function () {
                    var _self = this;
                    if (_self.OldPwd.length <= 0) {
                        layer.msg("原密码不能为空", { icon: 2 });
                        return false;
                    }
                    if (_self.Pwd1.length <= 0) {
                        layer.msg("密码不能为空", { icon: 2 });
                        return false;
                    }
                    if (_self.Pwd2 !== _self.Pwd1) {
                        layer.msg("两次输入密码不一致", { icon: 2 });
                        return false;
                    }
                    if (_self.Pwd2 == _self.OldPwd) {
                        layer.msg("新密码与旧密码一致", { icon: 2 });
                        return false;
                    }
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    var data = {
                        id: _self.UserId,
                        UserName: _self.UserName,
                        UserNickname: _self.UserNickname,
                        Pwd: _self.Pwd2,
                        Sort: _self.OldPwd,
                    };
                    yui.$axiospostform('/User/UpdatePwd', data)
                        .then(function (response) {
                            if (response.data.Item1 === 101) {
                                layer.tips(response.data.Item2, '.layui-layer-setwin', {
                                    tips: [1, '#3595CC'],
                                    time: 3000
                                });
                                layer.close(index);
                                return false;
                            }
                            if (response.data.Item1) {
                                layer.msg(response.data.Item2, { icon: 1, time: 1000 });
                                setTimeout(function () {
                                    yui.layer_close3();
                                }, 500);
                            } else {
                                layer.msg(response.data.Item2, { icon: 5 });
                            }
                            layer.close(index);
                        })
                        .catch(function (error) {
                            layer.close(index);
                        });
                }
            }
        });
    </script>
}